package com.sh.weblogspringboot.common.domain.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sh.weblogspringboot.common.domain.dos.ArticleContentDO;
import org.springframework.stereotype.Repository;


/**
 * @author songHai
 * @Classname ArticleContentMapper
 * @Description
 * @Date 2025/4/8 23:03
 */
@Repository
public interface ArticleContentMapper extends BaseMapper<ArticleContentDO> {

    /**
     * 根据文章 ID删除记录.
     *
     * @param articleId
     * @return
     */
    default int deleteByArticleId(Long articleId) {
        return delete(Wrappers.<ArticleContentDO>lambdaQuery().eq(ArticleContentDO::getArticleId, articleId));
    }

    /**
     * 根据文章ID查询
     *
     * @param articleId
     * @return
     */
    default ArticleContentDO selectByArticleId(Long articleId) {
        return selectOne(Wrappers.<ArticleContentDO>lambdaQuery().eq(ArticleContentDO::getArticleId, articleId));
    }

    /**
     * 通过文章 ID 更新
     *
     * @param articleContentDO
     */
    default int updateByArticleId(ArticleContentDO articleContentDO) {
        return update(articleContentDO, Wrappers.<ArticleContentDO>lambdaQuery().eq(ArticleContentDO::getArticleId, articleContentDO.getArticleId()));
    }
}
